
import { _decorator, Component, Node, Event, EventTouch, director, Label, Vec3, UITransform, Camera, view, View } from 'cc';
import { BaseObject } from '../modules/baseObject';
const { ccclass, property } = _decorator;

@ccclass('cameraManager')
export default class cameraManager extends BaseObject {

    @property(Camera)
    mainCamera: Camera = null!


    public worldToScreen(worldPos: Vec3 | Readonly<Vec3>, out?: Vec3) {
        return this.mainCamera.worldToScreen(worldPos, out);
    }

    /// <summary>
    ///判断世界坐标系内的一个点,摄像机是否可见
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public isVisibleOn3dCamera(pos: Vec3): boolean {
        if (!this.mainCamera) return false;
        let screenPos = this.mainCamera.worldToScreen(pos);
        let width = View.instance.getVisibleSize().width;
        let height = View.instance.getVisibleSize().height;
        if (screenPos.x < 0 || screenPos.x > width || screenPos.y < 0 || screenPos.y > height) {
            return false;
        }
        else {
            return true;
        }
    }

}